/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.DaftarPegawai;

import com.entities.Pegawai;
import com.entities.pegawaiTableModel;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;

/**
 *
 * @author Ignacio
 */
public class daftarPegawaiControl {
    private static javax.swing.JFrame frame;
    public daftarPegawaiControl (){
        
    }
    public static void hapusPegawai(String nip) throws SQLException, ClassNotFoundException{
        Pegawai.getKoneksiKontrol().deletePegawai(nip);
    }
    
//    public static JTable getPegawai(JTable tabelPegawai) throws ClassNotFoundException, SQLException{
//        try {
//            List<Pegawai> pegawaiList;
//              pegawaiList = Pegawai.getKoneksiKontrol().ambilPegawai();
//                pegawaiTableModel model = new pegawaiTableModel(pegawaiList);
//                tabelPegawai.setModel(model);
//        } catch (ClassNotFoundException ex) {
//            Logger.getLogger(daftarPegawaiControl.class.getName()).log(Level.SEVERE, null, ex);
//        }
//        return  tabelPegawai;
//    }
    
    public static void hapusPegawaiAction(JTable tab){
        String nip=(String) tab.getValueAt(tab.getSelectedRow(), 0);
        try {
            daftarPegawaiControl.hapusPegawai(nip);
        } catch (SQLException ex) {
            Logger.getLogger(daftarPegawaiControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(daftarPegawaiControl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static List<Pegawai> selectPegawai(String nip) throws ClassNotFoundException, SQLException{
        return Pegawai.getKoneksiKontrol().selectPegawai(nip);
        
    }
    
    public static List<Pegawai> selectPegawaiAction (JTable tab) {
       String nip=(String) tab.getValueAt(tab.getSelectedRow(), 0);
       List<Pegawai> returned = new ArrayList<Pegawai>();
        try {
            returned = selectPegawai(nip);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(daftarPegawaiControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(daftarPegawaiControl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return returned;
    }
    
    public static javax.swing.JFrame getFrame() {
        return frame;
    }
    
    public static void setForm (daftarPegawaiForm form){
        daftarPegawaiControl.frame = form;
    }
    
    
}
